#include "gd32f30x.h"
#include "stdint.h"
#include "stdio.h"
#include "DevicesQueue.h"
#include "DevicesModbus.h"
#include "DevicesUart.h"
#include "DevicesRS485.h"
#include "DevicesSoftTimer.h"

//#include "DriverModbus.h"

#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"

#include "taskSensor.h"
#include "taskMessageSlave.h"


/* 通信消息解析任务句柄 */
TaskHandle_t g_TaskMessageSlaveHand = NULL;


/* 解析缓存长度 */
#define MESSAGE_ANALYSIS_BUFF_LENGTH 256
/* 解析缓存 */
static uint8_t st_ucMessageAnalysisBuff[MESSAGE_ANALYSIS_BUFF_LENGTH];


void vTaskMessageSlave(void *pvParameters)
{
    uint32_t uiNotifiedValue = 0;
    int32_t iLength = 0;

    while (1)
    {
        /* 等待任务消息 */
        xTaskNotifyWait(0x00000000, 0xFFFFFFFF, &uiNotifiedValue, 100 / portTICK_RATE_MS);

        /* 读取并解析 上位机 发送过来的数据 */
        while((iLength = iQueueGetLengthOfOccupy(&g_TypeQueueUart2Read)) != 0)
        {
            iLength = (iLength > MESSAGE_ANALYSIS_BUFF_LENGTH) ? MESSAGE_ANALYSIS_BUFF_LENGTH : iLength;

//            enumQueuePopDatas(&g_TypeQueueUart2Read, st_ucMessageAnalysisBuff, iLength);

//            vUartDMASendDatas(USART2, st_ucMessageAnalysisBuff, iLength);
        }
    }
}
